<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.8"/>
<title>AndBase开发框架: com.google.gson.internal.bind.MapTypeAdapterFactory类 参考</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="ic_launcher.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">AndBase开发框架
   &#160;<span id="projectnumber">1.6</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.8 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'搜索');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>首页</span></a></li>
      <li><a href="pages.html"><span>相关页面</span></a></li>
      <li><a href="namespaces.html"><span>命名空间</span></a></li>
      <li class="current"><a href="annotated.html"><span>类</span></a></li>
      <li><a href="files.html"><span>文件</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="搜索" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>类列表</span></a></li>
      <li><a href="classes.html"><span>类索引</span></a></li>
      <li><a href="hierarchy.html"><span>类继承关系</span></a></li>
      <li><a href="functions.html"><span>类成员</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>全部</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>类</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>命名空间</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>文件</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>函数</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>变量</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>枚举值</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>页</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="namespacecom.html">com</a></li><li class="navelem"><a class="el" href="namespacecom_1_1google.html">google</a></li><li class="navelem"><a class="el" href="namespacecom_1_1google_1_1gson.html">gson</a></li><li class="navelem"><a class="el" href="namespacecom_1_1google_1_1gson_1_1internal.html">internal</a></li><li class="navelem"><a class="el" href="namespacecom_1_1google_1_1gson_1_1internal_1_1bind.html">bind</a></li><li class="navelem"><a class="el" href="classcom_1_1google_1_1gson_1_1internal_1_1bind_1_1_map_type_adapter_factory.html">MapTypeAdapterFactory</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#nested-classes">类</a> &#124;
<a href="#pub-methods">Public 成员函数</a> &#124;
<a href="#pac-methods">包函数</a> &#124;
<a href="#pri-methods">Private 成员函数</a> &#124;
<a href="#pri-static-methods">静态 Private 成员函数</a> &#124;
<a href="#pri-attribs">Private 属性</a> &#124;
<a href="classcom_1_1google_1_1gson_1_1internal_1_1bind_1_1_map_type_adapter_factory-members.html">所有成员列表</a>  </div>
  <div class="headertitle">
<div class="title">com.google.gson.internal.bind.MapTypeAdapterFactory类 参考</div>  </div>
</div><!--header-->
<div class="contents">
<div class="dynheader">
类 com.google.gson.internal.bind.MapTypeAdapterFactory 继承关系图:</div>
<div class="dyncontent">
 <div class="center">
  <img src="classcom_1_1google_1_1gson_1_1internal_1_1bind_1_1_map_type_adapter_factory.png" usemap="#com.google.gson.internal.bind.MapTypeAdapterFactory_map" alt=""/>
  <map id="com.google.gson.internal.bind.MapTypeAdapterFactory_map" name="com.google.gson.internal.bind.MapTypeAdapterFactory_map">
<area href="interfacecom_1_1google_1_1gson_1_1_type_adapter_factory.html" alt="com.google.gson.TypeAdapterFactory" shape="rect" coords="0,0,328,24"/>
</map>
 </div></div>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
类</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">class &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcom_1_1google_1_1gson_1_1internal_1_1bind_1_1_map_type_adapter_factory_1_1_adapter_3_01_k_00_01_v_01_4.html">Adapter&lt; K, V &gt;</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public 成员函数</h2></td></tr>
<tr class="memitem:a3886465fdad991079421d9d66ec246c1"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcom_1_1google_1_1gson_1_1internal_1_1bind_1_1_map_type_adapter_factory.html#a3886465fdad991079421d9d66ec246c1">MapTypeAdapterFactory</a> (<a class="el" href="classcom_1_1google_1_1gson_1_1internal_1_1_constructor_constructor.html">ConstructorConstructor</a> <a class="el" href="classcom_1_1google_1_1gson_1_1internal_1_1bind_1_1_map_type_adapter_factory.html#a5ccbdfa2429af8bdc49a1d5ceb610674">constructorConstructor</a>, boolean <a class="el" href="classcom_1_1google_1_1gson_1_1internal_1_1bind_1_1_map_type_adapter_factory.html#a5826110a2beb4bee302e0614b4d1b41a">complexMapKeySerialization</a>)</td></tr>
<tr class="separator:a3886465fdad991079421d9d66ec246c1"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pac-methods"></a>
包函数</h2></td></tr>
<tr class="memitem:a64975b8a0585ae29803d258f39c93346"><td class="memItemLeft" align="right" valign="top">public&lt; T &gt; TypeAdapter&lt; T &gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcom_1_1google_1_1gson_1_1internal_1_1bind_1_1_map_type_adapter_factory.html#a64975b8a0585ae29803d258f39c93346">create</a> (<a class="el" href="classcom_1_1google_1_1gson_1_1_gson.html">Gson</a> gson, TypeToken&lt; T &gt; typeToken)</td></tr>
<tr class="separator:a64975b8a0585ae29803d258f39c93346"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pri-methods"></a>
Private 成员函数</h2></td></tr>
<tr class="memitem:a011481ff3885824f4ac7b3921d885f8a"><td class="memItemLeft" align="right" valign="top">TypeAdapter&lt;?&gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcom_1_1google_1_1gson_1_1internal_1_1bind_1_1_map_type_adapter_factory.html#a011481ff3885824f4ac7b3921d885f8a">getKeyAdapter</a> (<a class="el" href="classcom_1_1google_1_1gson_1_1_gson.html">Gson</a> context, Type keyType)</td></tr>
<tr class="separator:a011481ff3885824f4ac7b3921d885f8a"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pri-static-methods"></a>
静态 Private 成员函数</h2></td></tr>
<tr class="memitem:ac7896b2e4a144a6cdd070987579fe586"><td class="memItemLeft" align="right" valign="top">static&lt; T &gt; <a class="el" href="classcom_1_1google_1_1gson_1_1_json_element.html">JsonElement</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcom_1_1google_1_1gson_1_1internal_1_1bind_1_1_map_type_adapter_factory.html#ac7896b2e4a144a6cdd070987579fe586">toJsonTree</a> (TypeAdapter&lt; T &gt; typeAdapter, T value)</td></tr>
<tr class="separator:ac7896b2e4a144a6cdd070987579fe586"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pri-attribs"></a>
Private 属性</h2></td></tr>
<tr class="memitem:a5ccbdfa2429af8bdc49a1d5ceb610674"><td class="memItemLeft" align="right" valign="top">final <a class="el" href="classcom_1_1google_1_1gson_1_1internal_1_1_constructor_constructor.html">ConstructorConstructor</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcom_1_1google_1_1gson_1_1internal_1_1bind_1_1_map_type_adapter_factory.html#a5ccbdfa2429af8bdc49a1d5ceb610674">constructorConstructor</a></td></tr>
<tr class="separator:a5ccbdfa2429af8bdc49a1d5ceb610674"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a5826110a2beb4bee302e0614b4d1b41a"><td class="memItemLeft" align="right" valign="top">final boolean&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcom_1_1google_1_1gson_1_1internal_1_1bind_1_1_map_type_adapter_factory.html#a5826110a2beb4bee302e0614b4d1b41a">complexMapKeySerialization</a></td></tr>
<tr class="separator:a5826110a2beb4bee302e0614b4d1b41a"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">详细描述</h2>
<div class="textblock"><p>Adapts maps to either JSON objects or JSON arrays.</p>
<h3>Maps as JSON objects</h3>
<p>For primitive keys or when complex map key serialization is not enabled, this converts Java <a class="el" href="">Maps</a> to JSON Objects. This requires that map keys can be serialized as strings; this is insufficient for some key types. For example, consider a map whose keys are points on a grid. The default JSON form encodes reasonably: </p><pre><div class="fragment"><div class="line">Map&lt;Point, String&gt; original = <span class="keyword">new</span> LinkedHashMap&lt;Point, String&gt;();</div>
<div class="line">original.put(<span class="keyword">new</span> Point(5, 6), <span class="stringliteral">&quot;a&quot;</span>);</div>
<div class="line">original.put(<span class="keyword">new</span> Point(8, 8), <span class="stringliteral">&quot;b&quot;</span>);</div>
<div class="line">System.out.println(gson.toJson(original, type));</div>
</div><!-- fragment --> </pre><p> The above code prints this JSON object:</p><pre><div class="fragment"><div class="line">{</div>
<div class="line">  <span class="stringliteral">&quot;(5,6)&quot;</span>: <span class="stringliteral">&quot;a&quot;</span>,</div>
<div class="line">  <span class="stringliteral">&quot;(8,8)&quot;</span>: <span class="stringliteral">&quot;b&quot;</span></div>
<div class="line">}</div>
</div><!-- fragment --> </pre><p> But GSON is unable to deserialize this value because the JSON string name is just the <a class="el" href="">toString()</a> of the map key. Attempting to convert the above JSON to an object fails with a parse exception: </p><pre><a class="el" href="classcom_1_1google_1_1gson_1_1_json_parse_exception.html">com.google.gson.JsonParseException</a>: Expecting object found: "(5,6)"
  at com.google.gson.JsonObjectDeserializationVisitor.visitFieldUsingCustomHandler
  at com.google.gson.ObjectNavigator.navigateClassFields
  ...</pre><h3>Maps as JSON arrays</h3>
<p>An alternative approach taken by this type adapter when it is required and complex map key serialization is enabled is to encode maps as arrays of map entries. Each map entry is a two element array containing a key and a value. This approach is more flexible because any type can be used as the map's key; not just strings. But it's also less portable because the receiver of such JSON must be aware of the map entry convention.</p>
<p>Register this adapter when you are creating your GSON instance. </p><pre><div class="fragment"><div class="line">Gson gson = <span class="keyword">new</span> GsonBuilder()</div>
<div class="line">  .registerTypeAdapter(Map.class, <span class="keyword">new</span> MapAsArrayTypeAdapter())</div>
<div class="line">  .create();</div>
</div><!-- fragment --> </pre><p> This will change the structure of the JSON emitted by the code above. Now we get an array. In this case the arrays elements are map entries: </p><pre><div class="fragment"><div class="line">[</div>
<div class="line">  [</div>
<div class="line">    {</div>
<div class="line">      <span class="stringliteral">&quot;x&quot;</span>: 5,</div>
<div class="line">      <span class="stringliteral">&quot;y&quot;</span>: 6</div>
<div class="line">    },</div>
<div class="line">    <span class="stringliteral">&quot;a&quot;</span>,</div>
<div class="line">  ],</div>
<div class="line">  [</div>
<div class="line">    {</div>
<div class="line">      <span class="stringliteral">&quot;x&quot;</span>: 8,</div>
<div class="line">      <span class="stringliteral">&quot;y&quot;</span>: 8</div>
<div class="line">    },</div>
<div class="line">    <span class="stringliteral">&quot;b&quot;</span></div>
<div class="line">  ]</div>
<div class="line">]</div>
</div><!-- fragment --> </pre><p> This format will serialize and deserialize just fine as long as this adapter is registered. </p>
</div><h2 class="groupheader">构造及析构函数说明</h2>
<a class="anchor" id="a3886465fdad991079421d9d66ec246c1"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">com.google.gson.internal.bind.MapTypeAdapterFactory.MapTypeAdapterFactory </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classcom_1_1google_1_1gson_1_1internal_1_1_constructor_constructor.html">ConstructorConstructor</a>&#160;</td>
          <td class="paramname"><em>constructorConstructor</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">boolean&#160;</td>
          <td class="paramname"><em>complexMapKeySerialization</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

</div>
</div>
<h2 class="groupheader">成员函数说明</h2>
<a class="anchor" id="a64975b8a0585ae29803d258f39c93346"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">public&lt;T&gt; TypeAdapter&lt;T&gt; com.google.gson.internal.bind.MapTypeAdapterFactory.create </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classcom_1_1google_1_1gson_1_1_gson.html">Gson</a>&#160;</td>
          <td class="paramname"><em>gson</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">TypeToken&lt; T &gt;&#160;</td>
          <td class="paramname"><em>type</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">package</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Returns a type adapter for</p><div class="fragment"><div class="line">type </div>
</div><!-- fragment --><p> , or null if this factory doesn't support</p><div class="fragment"><div class="line">type </div>
</div><!-- fragment --><p> . </p>

<p>实现了 <a class="el" href="interfacecom_1_1google_1_1gson_1_1_type_adapter_factory.html#a8f4c55ec13b384a3e1cba3c3a827ee48">com.google.gson.TypeAdapterFactory</a>.</p>

</div>
</div>
<a class="anchor" id="a011481ff3885824f4ac7b3921d885f8a"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">TypeAdapter&lt;?&gt; com.google.gson.internal.bind.MapTypeAdapterFactory.getKeyAdapter </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classcom_1_1google_1_1gson_1_1_gson.html">Gson</a>&#160;</td>
          <td class="paramname"><em>context</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">Type&#160;</td>
          <td class="paramname"><em>keyType</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Returns a type adapter that writes the value as a string. </p>

</div>
</div>
<a class="anchor" id="ac7896b2e4a144a6cdd070987579fe586"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">static &lt;T&gt; <a class="el" href="classcom_1_1google_1_1gson_1_1_json_element.html">JsonElement</a> com.google.gson.internal.bind.MapTypeAdapterFactory.toJsonTree </td>
          <td>(</td>
          <td class="paramtype">TypeAdapter&lt; T &gt;&#160;</td>
          <td class="paramname"><em>typeAdapter</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">T&#160;</td>
          <td class="paramname"><em>value</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">static</span><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

</div>
</div>
<h2 class="groupheader">类成员变量说明</h2>
<a class="anchor" id="a5826110a2beb4bee302e0614b4d1b41a"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">final boolean com.google.gson.internal.bind.MapTypeAdapterFactory.complexMapKeySerialization</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

</div>
</div>
<a class="anchor" id="a5ccbdfa2429af8bdc49a1d5ceb610674"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">final <a class="el" href="classcom_1_1google_1_1gson_1_1internal_1_1_constructor_constructor.html">ConstructorConstructor</a> com.google.gson.internal.bind.MapTypeAdapterFactory.constructorConstructor</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

</div>
</div>
<hr/>该类的文档由以下文件生成:<ul>
<li>src/com/google/gson/internal/bind/<a class="el" href="_map_type_adapter_factory_8java.html">MapTypeAdapterFactory.java</a></li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
生成于 2014年 十一月 6日 星期四 11:22:04 , 为 AndBase开发框架使用  &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.8
</small></address>
</body>
</html>
